<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="base/layout.html">

<!-- start: Content -->
<div layout:fragment="content" class="main sidebar-minified">

    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a th:href="@{../infoManage/indexTotal}">首页</a></li>
                <li><i class="fa fa-table"></i>企业实践管理</li>
            </ol>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>查询信息</strong></h2>
                </div>
                <div class="panel-body">
                    <form id="modularForm" th:action="@{../practiceManageInfo/queryPracticeManageInfo}" method="post"
                          class="form-horizontal " role="form">
                        <div class="form-group">

                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">学院</label>
                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectDepartment" name="departmentid" class="form-control" size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">专业</label>
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectMajor" name="majorid" class="form-control" size="1">

                                        </select>
                                    </div>

                                    <button id="submitBtn" type="submit" class="btn btn-sm btn-success"><i
                                            class="fa fa-dot-circle-o"></i> 查询
                                    </button>
                                    <button id="resetBtn" type="button" class="btn btn-sm btn-danger"><i
                                            class="fa fa-ban"></i> 重置
                                    </button>
                                    <button id="exportBtn" type="button" class="btn btn-sm btn-primary"><i
                                            class="fa fa-ban"></i> 导出excel
                                    </button>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">时间</label>
                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <input type="text" class="form-control date-picker" id="practiceTimePlan"
                                               name="practicetimeplan" readonly
                                               th:value="${queryMap['practicetimeplan']}" placeholder="计划时间">
                                    </div>
                                    <label class="col-lg-1 col-md-1 col-sm-1 control-label"
                                           style="text-align: center">-</label>
                                    <div class="col-lg-2 col-md-2">
                                        <input type="text" class="form-control date-picker" id="practiceTimeActual"
                                               name="practicetimeactual" readonly
                                               th:value="${queryMap['practicetimeactual']}" placeholder="实际时间">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-table red"></i><span class="break"></span><strong>企业实践管理</strong></h2>

                </div>
                <div class="panel-body">
                    <table class="table table-striped table-bordered bootstrap-datatable datatable">
                        <thead>
                        <tr>
                            <td>序号</td>
                            <th>学院</th>
                            <th>专业</th>
                            <th>基地名称</th>
                            <th>计划时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="practiceManageInfo,state  : ${practiceManageInfoList}">
                            <td th:text="${state.index+1}"></td>
                            <td th:if="${#lists.isEmpty(practiceManageInfo.department)}"></td>
                            <td th:unless="${#lists.isEmpty(practiceManageInfo.department)}"
                                th:text="${practiceManageInfo.department.department}"></td>
                            <td th:if="${#lists.isEmpty(practiceManageInfo.major)}"></td>
                            <td th:unless="${#lists.isEmpty(practiceManageInfo.major)}"
                                th:text="${practiceManageInfo.major.majorname}"></td>
                            <td th:text="${practiceManageInfo.basename}"></td>
                            <td th:text="${#dates.format(practiceManageInfo.practicetimeplan,'yyyy-MM-dd')}"></td>

                            <td>
                                <a class="btn btn-success"
                                   th:onclick="'layerOpen(\'toPracticeManageInfoDetail?id='+${practiceManageInfo.id}+'\')'">
                                    <i class="fa fa-search-plus "></i>
                                </a>
                                <a th:if="${session.userInfo.departmentid == practiceManageInfo.departmentid||session.userInfo.departmentid == 11 }"
                                   class="btn btn-info"
                                   th:href="@{../practiceManageInfo/toPracticeManageInfoUpdate(id=${practiceManageInfo.id})}">
                                    <i class="fa fa-edit "></i>
                                </a>
                                <a th:if="${session.userInfo.departmentid == practiceManageInfo.departmentid||session.userInfo.departmentid == 11 }"
                                   class="btn btn-danger"
                                   th:onclick="'deletePracticeManageInfo('+${practiceManageInfo.id}+')'">
                                    <i class="fa fa-trash-o "></i>
                                </a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <!-- 分页 -->
                    <div th:unless="${#lists.isEmpty(practiceManageInfoList)}">
                        <div
                                th:replace="base/pagination :: pagination('queryPracticeManageInfo')"></div>
                    </div>
                </div>
            </div>
        </div><!--/col-->
    </div><!--/row-->

    <script>
        $(document).ready(function () {
            //加载学院
            initDepartment();
            //加载专业
            initMajor();
            //加载时间控件
            setDatePicker("#practiceTimePlan");
            setDatePicker("#practiceTimeActual");
        })


        function initDepartment() {
            $("#selectDepartment").append("<option value=-1>请选择</option>");
            //获取学院id
            var departmentid = "[[${queryMap['departmentid']}]]";
            /*var majorid = "[[${queryMap['majorid']}]]";*/
            $.ajax({
                url: '../department/selectDepartmentInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    //如果学院id是空
                    if (departmentid == undefined || departmentid == null || departmentid == "") {
                        for (var i in data) {
                            $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {
                            if (departmentid == data[i].id) {
                                $("#selectDepartment").append("<option value=" + data[i].id + " selected>" + data[i].department + "</option>");
                            }
                            else {
                                $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");
                            }
                        }
                    }
                }
            })
            $("#selectDepartment").change(function () {
                $("#selectMajor").empty();
                $("#selectMajor").append("<option value=-1>请选择</option>");
                var str = $("#selectDepartment").find("option:selected").val();
                if (str > 9) {
                    $("#selectMajor").empty();
                    $("#selectMajor").append("<option value=-1>无</option>");
                   /* $.ajax({
                        url: '../major/selectMajorInfo',
                        type: 'get',
                        dataType: 'json',
                        data: {},
                        success: function (data) {
                            //如果专业id是空
                            if (majorid == undefined || majorid == null || majorid == "") {
                                for (var i in data) {
                                    $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                                }
                            } else {
                                for (var i in data) {
                                    if (majorid == data[i].id) {
                                        $("#selectMajor").append("<option value=" + data[i].id + " selected>" + data[i].majorname + "</option>");
                                    }
                                    else {
                                        $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                                    }
                                }
                            }
                        }
                    })*/
                } else if (str==-1) {
                    $("#selectMajor").empty();
                    $("#selectMajor").append("<option value=-1>请先选择学院</option>");
                }else{
                    $.ajax({
                        url: '../major/selectMajor',
                        type: 'post',
                        data: {'departmentid': $("select[name='departmentid']").val()},
                        success: function (data) {
                            for (var i in data) {
                                $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                            }
                        }
                    })
                }
            })
        }

        //加载专业
        function initMajor() {
            var t;
            //获取专业id
            var majorid = "[[${queryMap['majorid']}]]";
            t = setTimeout(function () {
                var str = $("#selectDepartment").find("option:selected").val();
                if (str == -1) {
                    $("#selectMajor").empty();
                    $("#selectMajor").append("<option value=-1>请先选择学院</option>");
                    /*$.ajax({
                        url: '../major/selectMajorInfo',
                        type: 'get',
                        dataType: 'json',
                        data: {},
                        success: function (data) {
                            //如果专业id是空
                            if (majorid == undefined || majorid == null || majorid == "") {
                                for (var i in data) {
                                    $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                                }
                            } else {
                                for (var i in data) {
                                    if (majorid == data[i].id) {
                                        $("#selectMajor").append("<option value=" + data[i].id + " selected>" + data[i].majorname + "</option>");
                                    }
                                    else {
                                        $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                                    }
                                }
                            }
                        }
                    })*/
                } else if (str>9) {
                    $("#selectMajor").empty();
                    $("#selectMajor").append("<option value=-1>无</option>");
                }else{
                    $("#selectMajor").append("<option value=-1>请选择</option>");
                    $.ajax({
                        url: '../major/selectMajor',
                        type: 'post',
                        data: {'departmentid': $("select[name='departmentid']").val()},
                        success: function (data) {
                            for (var i in data) {
                                if (majorid == data[i].id) {
                                    $("#selectMajor").append("<option value=" + data[i].id + " selected>" + data[i].majorname + "</option>");
                                }
                                else {
                                    $("#selectMajor").append("<option value=" + data[i].id + ">" + data[i].majorname + "</option>");
                                }
                            }
                        }
                    })
                }
            },100),
                function () {
                    clearTimeout(t);
                }
        }

        function deletePracticeManageInfo(id) {
            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);
                $.ajax({
                    url: 'deletePracticeManageInfo',
                    type: 'get',
                    data: 'id=' + id,
                    success: function () {
                        layer.msg("删除成功!");
                        location.reload();
                    }
                })
            }, function () {
                //取消
            });
        }

        //重置按钮
        $("#resetBtn").on("click", function () {
            $("#selectMajor").empty();
            $("#selectMajor").append("<option value=-1>请先选择学院</option>");
            $("#selectDepartment").val("-1");
            $("#practiceTimePlan").val("");
            $("#practiceTimeActual").val("");
        });


        //导出excel
        $("#exportBtn").on("click", function () {
            //查询条件是空则不允许导出
            var selectDepartment = $("#selectDepartment").val();
            var selectMajor = $("#selectMajor").val();
            var practicetimeplan = $("#practicetimeplan").val();
            var practicetimeactual = $("#practicetimeactual").val();
            if (selectDepartment == -1 && (practicetimeplan == undefined || practicetimeplan == null || practicetimeplan == "")
                && (practicetimeactual == undefined || practicetimeactual == null || practicetimeactual == "")
                && selectMajor == -1) {
                layer.msg("查询条件不能为空");
            }
            else {
                $("#modularForm").attr("action", "exportExcel");
                $("#modularForm").submit();
                $("#modularForm").attr("action", "queryPracticeManageInfo");
            }
        });
    </script>
</div>

